﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessInstockGroup
// 文件功能描述：食材入库数据访问层
//
// 
// 创建标识：2012-01-14 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO.WaiGaoQiao;
using System.Data;


namespace Model.WaiGaoQiao
{
    public class InstockGroupInfo : IngredientsAbstract
    {        
        public InstockGroupInfo(bool isgetcount)
        {
            DAIG = new DataAccessInstockGroup();
            if (isgetcount)
            {
                rowcount = DAIG.GetRowCount();
            }
        }

        public InstockGroupInfo()
        {

        }


        /// <summary>
        /// 保存食材入库
        /// </summary>
        /// <param name="instginfo"></param>
        /// <returns></returns>
        public override int SaveInstockGroup(IngredientsAbstract instginfo)
        {
            object[] igpara = new object[] { instginfo.ID, instginfo.Ord_No, instginfo.Supplier_ID, instginfo.Operator_ID,
                                             instginfo.GoodsType, instginfo.Remark, instginfo.RecordDateTime };
            return DAIG.SaveInstockGroup(igpara);
        }

        /// <summary>
        /// 删除食材入库
        /// 同时删除食材明细
        /// </summary>
        /// <param name="ID">主键</param>
        /// <returns></returns>
        public override int DeleteInstockGroup(string OrdNo)
        {
            return DAIG.DeleteInstockGroup(OrdNo);
        }


        /// <summary>
        /// 获取一条食材入库信息
        /// </summary>
        /// <param name="ID">主键</param>
        /// <returns>食材入库信息</returns>
        public override IngredientsAbstract GetInstockGroupInfo(int ID)
        {
            DataSet ds = DAIG.GetInstockGroup(ID);
            IList<IngredientsAbstract> list = ReadDataSet(ds);
            return  list.Count > 0 ? list[0] : new InstockGroupInfo();
        }    

        /// <summary>
        /// 获取食材入库信息
        /// </summary>
        /// <param name="pagesize">页大小</param>
        /// <param name="startindex">起始页</param>
        /// <param name="dict">查询条件</param>
        /// <returns>食材入库信息</returns>
        public override IList<IngredientsAbstract> GetInstockGroupInfo(int pagesize, int startindex, 
                                                                       IngredientsAbstract instockGroupInfo)
        {
            StringBuilder condition = new StringBuilder();
            condition.Append(" and ord_no like '%");
            condition.Append(instockGroupInfo.Ord_No);
            condition.Append("%'");
            if (instockGroupInfo.GetType().Name == "ConsumablesInfo") //易耗品
            {
                condition.Append(" and GoodsType = '1'");
            }
            else if (instockGroupInfo.GetType().Name == "InstockGroupInfo") //非易耗品
            {
                condition.Append(" and GoodsType = '2'");
            }            
            DataSet ds = DAIG.GetInstockGroup(pagesize, startindex, condition.ToString());
            return ReadDataSet(ds);
        }

        /// <summary>
        /// 获取食材主表的数据
        /// </summary>
        /// <returns></returns>
        public override int GetRowCount()
        {
            return DAIG.GetRowCount();
        }

    }
}
